﻿using NB.MGJ.FrameWork;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
namespace NB.MGJ.Service
{
     public partial class FleeGoodsService
    {
         public BaseRepository _baseRepository = new BaseRepository();
         /// <summary>
         /// 将物流码写入文本
         /// </summary>
         /// <param name="arr"></param>
         /// <returns></returns>
         public string WriteTxt(string[] arr, string filename)
         {
             //在将文本写入文件前，处理文本行
             //StreamWriter一个参数默认覆盖
             //StreamWriter第二个参数为false覆盖现有文件，为true则把文本追加到文件末尾
             try
             {
                 string folder=ConfigurationManager.AppSettings["UpLoadFiles"];
                 if (!Directory.Exists(folder))
                 {
                     Directory.CreateDirectory(folder);
                 }
                 string filePath = folder + filename;
                 using (System.IO.StreamWriter file = new System.IO.StreamWriter(filePath, true))
                 {
                     foreach (string line in arr)
                     {
                         if (!line.Contains("second"))
                         {
                             file.WriteLine(line);// 直接追加文件末尾，换行 
                         }
                     }
                 }
                 return filePath;
             }
             catch (Exception)
             {
                 return "";
             }

         }
    }
}
